package com.csw.rediscachedemo.redis;

public class Singleton {
    private static volatile Singleton sInstance;

    public static void main(String[] args) {
        Singleton singleton = getInstance();
    }

    public static Singleton getInstance() {
        //第一次验证是否为null
        if (sInstance == null) {
            //加锁
            synchronized (Singleton.class) {
                //第二次验证是否为null
                if (sInstance == null) {
                    //创建对象
                    sInstance = new Singleton();
                }
            }
        }
        return sInstance;
    }

}
